import 'package:aio/aio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/model/material_requisition_model.dart';
import 'package:app/src/ui/dialog/dailog.dart';
import 'package:app/src/ui/route/helper/route_helper.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';

import '../../../../../http/bean/worksdo/material_requisition_bean.dart';
import '../../../../../http/bean/wroks/dispatchingaudit_bean.dart';
import '../../../../../utils/unit_utils.dart';
import '../../../../app_ui.dart';

///物料请购
class UiMaterialAuditForm {
  static bool isModifyBeizhu = false; //备注是否可以修改
  static Widget build(
      BuildContext context, MaterialInfo? materialInfo, bool isBeizhu,
      {String? title}) {
    isModifyBeizhu = isBeizhu;
    return StatefulBuilder(builder: (context, setState) {
      List<Widget> children = [];
      if (StringUtils.isEmpty(title)) {
        title = AppStrings.of(context).MaterialInfo; //物料信息
      }
      children.add(UiBase.title(context, title,
          bottom: AppEdgeInsets.margin_bottom)); //标题
      children.add(_table(context, materialInfo!));
      var column = UiBase.column(context, children);
      var card = UiCard.build(context, column);
      return card;
    });
  }

  ///fixme Table表格里的行TabRow;每一行的表格数量必须相等。不然报错。
  ///fixme table嵌套table实现单元格合并。

  //表格线条颜色
  static Color _BorderColor = Colors.black12;

  //表格线条宽度
  static double _width = 1;

  ///背景色表格标题
  static Color _backgroundColorWithTableTitle = Colors.black12;
  static Color _backgroundColorWithWhite = Colors.white;
  static Color _backgroundColorWithGrey = ColorUtils.parseColor("#F7F6F3");
  static StateSetter? _setState = null;

  static Widget _table(BuildContext context, MaterialInfo materialInfo) {
    if (materialInfo?.PurDemandList == null ||
        materialInfo!.PurDemandList!.length <= 0) {
      return LibUi.getEmptyView();
    }
    //fixme 表格
    return StatefulBuilder(builder: (context, setState) {
      _setState = setState;
      //可以水平滑动的表格
      var scrolltable = _scrolltable(context, materialInfo);
      //水平滑动效果
      var singleChildScrollView = SingleChildScrollView(
          child: scrolltable, scrollDirection: Axis.horizontal);
      return Center(
        child: Container(
          child: singleChildScrollView,
          //width: 2400,
        ),
      );
    });
  }

  ///水平滑动表格
  static Widget _scrolltable(BuildContext context, MaterialInfo materialInfo) {
    if (materialInfo.PurDemandList == null ||
        materialInfo.PurDemandList!.length <= 0) {
      return AppUi.getEmptyView();
    }
    List<PurDemand> datas = materialInfo.PurDemandList!;
    var firstData = datas[0];
    var isAdd = materialInfo.isCanoOeration(); //是否可以添加(是否可操作)
    var children = <TableRow>[];
    //第一行标题栏
    List<Widget> titleChildren = [];
    if (isAdd) {
      titleChildren.add(_text("")); //加号
    }
    titleChildren.add(_text(AppStrings.of(context).TheSerial)); //序号
    titleChildren.add(_text(AppStrings.of(context).MaterialName3)); //物料名称
    titleChildren.add(_text(AppStrings.of(context).TypeOfMaterial)); //物料类型
    titleChildren.add(_text(AppStrings.of(context).MaterialCode)); //物料编码
    titleChildren.add(_text(AppStrings.of(context).Width_Height)); //规格型号
    if (firstData.Iswidth2()) {
      titleChildren.add(_text(AppStrings.of(context).ItemWidth)); //宽
    }
    if (firstData.Isheight2()) {
      titleChildren.add(_text(AppStrings.of(context).ItemHeight)); //高
    }
    if (firstData.Islength2()) {
      titleChildren.add(_text(AppStrings.of(context).long)); //长
    }
    if (firstData.Isthickness2()) {
      titleChildren.add(_text(AppStrings.of(context).thickness2)); //厚
    }
    if (firstData.Isquantity2()) {
      titleChildren.add(_text(AppStrings.of(context).ItemNum)); //数量
    }
    if (!firstData.isMT01()) {
      //辅料，五金；显示；包数量，和每包数量。
      titleChildren
          .add(_text(AppStrings.of(context).PackageCount, isStart: true)); //包数量
      titleChildren.add(
          _text(AppStrings.of(context).PackageListCount, isStart: true)); //每包数量
    }
    titleChildren.add(_text(AppStrings.of(context).NumberOfApplications,
        isStart: true)); //申请数量*
    titleChildren
        .add(_text(AppStrings.of(context).ApproveNum, isStart: false)); //批准数量
    if (firstData.isSubsidiaryNum()) {
      titleChildren.add(_text(AppStrings.of(context).Area)); //面积
    }
    titleChildren.add(_text(AppStrings.of(context).ManufacturerName)); //品牌
    titleChildren.add(_text(AppStrings.of(context).CurrentInventory)); //当前库存
    titleChildren.add(_text(AppStrings.of(context).Note)); //备注
    if (isAdd) {
      titleChildren.add(_text(AppStrings.of(context).Operation)); //操作
    }
    var tableRow = TableRow(
        decoration: BoxDecoration(color: _backgroundColorWithTableTitle),
        children: titleChildren);
    children.add(tableRow);
    //第二行，内容行。
    for (int i = 0; i < datas.length; i++) {
      var data = datas[i];
      List<Widget> rowChildren = [];
      //加号
      if (isAdd) {
        rowChildren.add(Row(
          children: [
            InkWell(
              child: Icon(
                Icons.add,
                color: Colors.blueAccent,
                size: 33,
              ),
              onTap: () {
                _setState?.call(() {
                  //复制
                  datas?.add(datas[i].copy());
                });
              },
            ),
          ],
        ));
      }
      //序号
      var TheSerial = _text("${i + 1}");
      rowChildren.add(TheSerial);
      //物料名称
      var MaterialName = _text("${data.MaterialName}");
      rowChildren.add(MaterialName);
      //物料类型
      var MaterialType = _text("${data.getMaterialTypeName(context)}");
      rowChildren.add(MaterialType);
      //物料编码
      var MaterialCode = _text("${data.MaterialCode}");
      rowChildren.add(MaterialCode);
      StateSetter? sizeSetState = null; //规格
      StateSetter? NumberOfApplications = null; //申请数量
      var isDemandNumUpdate = false; //是否实时修改申请数量
      StateSetter? CurrentInventorySetState = null; //库存数量
      StateSetter? SubsidiaryNumSetState = null; //辅助数量（原片里面是面积）
      bool readOnly = true; //只读
      if (firstData.isOperationSize()) {
        //规格型号,可手动填写。
        var Width_Height = StatefulBuilder(
          builder: (contxet, setState) {
            sizeSetState = setState;
            return UiBase.itemWithSigleEdit(context, data?.Size?.trim(),
                isAllowEmpty: true,
                isLine: true,
                readOnly: readOnly, onChanged: (value) {
              data?.Size = value;
              getStockNum(context, CurrentInventorySetState, data);

              ///库存数量
            });
          },
        );
        rowChildren.add(Width_Height);
      } else {
        //规格，不可填写
        var Width_Height = StatefulBuilder(
          builder: (contxet, setState) {
            sizeSetState = setState;
            if (firstData.isMT01()) {
              data?.Size = "${data?.Width}*${data?.Height}";
            }
            return _text(data?.Size);
          },
        );
        rowChildren.add(Width_Height);
      }
      if (firstData.Iswidth2()) {
        //宽
        if (firstData.Iswidth) {
          var _w = data?.getWidthInput();
          //原片
          var Width = UiBase.itemWithSigleEdit(
              context, StringUtils.toStringAsDecimal(_w),
              unit: data?.WidthUnit,
              isAllowEmpty: true,
              isDecimal: true,
              isNegative: false,
              readOnly: readOnly,
              isLine: true, onChanged: (value) {
            // if (StringUtils.isEmpty(value)) {
            //   data?.Width = "0"; //不能为空，为空，提交接口会报数据格式错误。
            // } else {
            //   data?.Width = value;
            // }

            if (StringUtils.isEmpty(value)) {
              data?.Width = "0"; //不能为空，为空，提交接口会报数据格式错误。
              data?.WidthInput = "0";
            } else {
              //data?.Width = value;
              data?.WidthInput = value;
              data?.Width =
                  AppUnitUtils.unittomm(data?.WidthUnit, value).toString();
            }

            sizeSetState?.call(() {}); //规格更新
            isDemandNumUpdate = true;
            NumberOfApplications?.call(() {}); //申请数量
            SubsidiaryNumSetState?.call(() {}); //原片辅助数量(面积)
            getStockNum(context, CurrentInventorySetState, data);

            ///库存数量
          });
          rowChildren.add(Width);
        } else {
          var _w = data?.getWidthInput();
          var ItemWidth = _text("$_w${data?.WidthUnit}");
          rowChildren.add(ItemWidth);
        }
      }
      if (firstData.Isheight2()) {
        //高
        if (firstData.Isheight) {
          var _h = data?.getHeightInput();
          //原片
          var Height = UiBase.itemWithSigleEdit(
              context, StringUtils.toStringAsDecimal(_h),
              unit: data?.HeightUnit,
              isAllowEmpty: true,
              isDecimal: true,
              isNegative: false,
              readOnly: readOnly,
              isLine: true, onChanged: (value) {
            // if (StringUtils.isEmpty(value)) {
            //   data?.Height = "0"; //不能为空，为空，提交接口会报数据格式错误。
            // } else {
            //   data?.Height = value;
            // }
            if (StringUtils.isEmpty(value)) {
              data?.Height = "0"; //不能为空，为空，提交接口会报数据格式错误。
              data?.HeightInput = "0";
            } else {
              //data?.Height = value;
              data?.HeightInput = value;
              data?.Height =
                  AppUnitUtils.unittomm(data?.HeightUnit, value).toString();
            }
            sizeSetState?.call(() {}); //规格更新
            isDemandNumUpdate = true;
            NumberOfApplications?.call(() {}); //申请数量
            SubsidiaryNumSetState?.call(() {}); //原片辅助数量(面积)
            getStockNum(context, CurrentInventorySetState, data);

            ///库存数量
          });
          rowChildren.add(Height);
        } else {
          var _h = data?.getHeightInput();
          var ItemHeight = _text("$_h${data?.HeightUnit}");
          rowChildren.add(ItemHeight);
        }
      }
      if (firstData.Islength2()) {
        if (firstData.Islength) {
          //长
          var Lengths = UiBase.itemWithSigleEdit(
              context, StringUtils.toStringAsDecimal(data?.getLengthsInput()),
              unit: data?.LengthUnit,
              isAllowEmpty: true,
              isDecimal: true,
              isNegative: false,
              readOnly: readOnly,
              isLine: true, onChanged: (value) {
            // if (StringUtils.isEmpty(value)) {
            //   data?.Lengths = "0"; //不能为空，为空，提交接口会报数据格式错误。
            // } else {
            //   data?.Lengths = value;
            // }
            if (StringUtils.isEmpty(value)) {
              data?.Lengths = "0"; //不能为空，为空，提交接口会报数据格式错误。
              data?.LengthsInput = "0";
            } else {
              //data?.Lengths = value;
              data?.LengthsInput = value;
              data?.Lengths =
                  AppUnitUtils.unittomm(data?.LengthUnit, value).toString();
            }
            isDemandNumUpdate = true;
            NumberOfApplications?.call(() {}); //申请数量
            ///sizeSetState?.call(() {}); //规格更新
            getStockNum(context, CurrentInventorySetState, data);

            ///库存数量
          });
          rowChildren.add(Lengths);
        } else {
          var long = _text(
              "${StringUtils.toStringAsDecimal(data?.Lengths)}${data?.LengthUnit}");
          rowChildren.add(long);
        }
      }
      if (firstData.Isthickness2()) {
        if (firstData.Isthickness && !firstData.isMT02()) {
          //厚;(辅料的厚度不允许修改。)
          var Thickness = UiBase.itemWithSigleEdit(
              context, StringUtils.toStringAsDecimal(data?.getThicknessInput()),
              unit: data?.ThicknessUnit,
              isAllowEmpty: true,
              isDecimal: true,
              isNegative: false,
              readOnly: readOnly,
              isLine: true, onChanged: (value) {
            // if (StringUtils.isEmpty(value)) {
            //   data?.Thickness = "0"; //不能为空，为空，提交接口会报数据格式错误。
            // } else {
            //   data?.Thickness = value;
            // }
            if (StringUtils.isEmpty(value)) {
              data?.Thickness = "0"; //不能为空，为空，提交接口会报数据格式错误。
              data?.ThicknessInput = "0";
            } else {
              //data?.Thickness = value;
              data?.ThicknessInput = value;
              data?.Thickness =
                  AppUnitUtils.unittomm(data?.ThicknessUnit, value).toString();
            }
            isDemandNumUpdate = true;
            NumberOfApplications?.call(() {}); //申请数量
            ///sizeSetState?.call(() {}); //规格更新
            getStockNum(context, CurrentInventorySetState, data);

            ///库存数量
          });
          rowChildren.add(Thickness);
        } else {
          //厚
          // var thickness = _text(StringUtils.toStringAsDecimal(data?.Thickness));
          var thickness = _text(
              "${StringUtils.toStringAsDecimal(data?.Thickness)}${data?.ThicknessUnit}");
          rowChildren.add(thickness);
        }
      }
      if (firstData.Isquantity2()) {
        if (firstData.Isquantity) {
          //数量
          var Numbers = UiBase.itemWithSigleEdit(
              context, StringUtils.toStringAsDecimal(data?.Numbers),
              unit: data?.QuantityUnit,
              isAllowEmpty: true,
              isDecimal: true,
              isNegative: false,
              readOnly: readOnly,
              isLine: true, onChanged: (value) {
            if (StringUtils.isEmpty(value)) {
              data?.Numbers = "0"; //不能为空，为空，提交接口会报数据格式错误。
            } else {
              data?.Numbers = value;
            }
            isDemandNumUpdate = true;
            NumberOfApplications?.call(() {}); //申请数量
            ///sizeSetState?.call(() {}); //规格更新
            getStockNum(context, CurrentInventorySetState, data);

            ///库存数量
          });
          rowChildren.add(Numbers);
        } else {
          //数量
          //var ItemNum = _text(StringUtils.toStringAsDecimal(data?.Numbers));
          var ItemNum = _text(data?.getNumbersStrAndUnit());
          rowChildren.add(ItemNum);
        }
      }
      if (!firstData.isMT01()) {
        //fixme 辅料，五金；显示；包数量，和每包数量。
        //包数量
        var PackageCount = StatefulBuilder(builder: (contxet, setState) {
          // PackageCountSetState = setState;
          // TextEditingController? _controller;
          // var _key = "PackageCount:${data?.ListId}${data?.index}_${i}";
          var PackageCount = UiBase.itemWithSigleEdit(
              context, StringUtils.toStringAsDecimal(data?.PackageCount),
              unit: data?.PackageUnit,
              readOnly: true,
              // onController: (value) {
              //   _controller = value;
              // },
              // mtextSelection: getTextSelection(_key),
              // focusNode: FocusNodeManager.getFocusNode(_key).addListener(
              //       (value) {
              //     if (value) {
              //       //聚焦
              //       setTextSelection(_key, _controller?.selection); //记录焦点位置
              //     } else {
              //       //失去焦点
              //       setTextSelection(_key, null);
              //     }
              //   },
              // ),
              isAllowEmpty: true,
              isDecimal: true,
              isNegative: false,
              isLine: true, onChanged: (value) {
            if (StringUtils.isEmpty(value)) {
              data?.PackageCount = "0"; //不能为空，为空，提交接口会报数据格式错误。
            } else {
              data?.PackageCount = value;
            }
            isDemandNumUpdate = false;
            data?.DemandNum = DecimalUtils.multiply(
                data?.toDouble(data?.PackageCount).toString(),
                data
                    ?.toDouble(data?.PackageListCount)
                    .toString()); //fixme 申请数量就等于包数量*每包数量
            data?.MinNum = data?.DemandNum;
            NumberOfApplications?.call(() {}); //申请数量
            ///sizeSetState?.call(() {}); //规格更新
            // getStockNum(
            //     context, CurrentInventorySetState, MaterialCodeSetState, data);

            ///库存数量
          });
          return PackageCount;
        });
        rowChildren.add(PackageCount);

        //每包数量
        var PackageListCount = StatefulBuilder(builder: (contxet, setState) {
          // PackageListCountSetState = setState;
          // TextEditingController? _controller;
          // var _key = "PackageListCount:${data?.ListId}${data?.index}_${i}";
          var _unit = "${data?.MainUnit}/${data?.PackageUnit}";
          var PackageListCount = UiBase.itemWithSigleEdit(
              context, StringUtils.toStringAsDecimal(data?.PackageListCount),
              unit: _unit,
              readOnly: true,
              // onController: (value) {
              //   _controller = value;
              // },
              // mtextSelection: getTextSelection(_key),
              // focusNode: FocusNodeManager.getFocusNode(_key).addListener(
              //       (value) {
              //     if (value) {
              //       //聚焦
              //       setTextSelection(_key, _controller?.selection); //记录焦点位置
              //     } else {
              //       //失去焦点
              //       setTextSelection(_key, null);
              //     }
              //   },
              // ),
              isAllowEmpty: true,
              isDecimal: true,
              isNegative: false,
              isLine: true, onChanged: (value) {
            if (StringUtils.isEmpty(value)) {
              data?.PackageListCount = "0"; //不能为空，为空，提交接口会报数据格式错误。
            } else {
              data?.PackageListCount = value;
            }
            isDemandNumUpdate = false;
            data?.DemandNum = DecimalUtils.multiply(
                data?.toDouble(data?.PackageCount).toString(),
                data
                    ?.toDouble(data?.PackageListCount)
                    .toString()); //fixme 申请数量就等于包数量*每包数量
            data?.MinNum = data?.DemandNum;
            NumberOfApplications?.call(() {}); //申请数量
            ///sizeSetState?.call(() {}); //规格更新
            // getStockNum(
            //     context, CurrentInventorySetState, MaterialCodeSetState, data);

            ///库存数量
          });
          return PackageListCount;
        });
        rowChildren.add(PackageListCount);
      }
      //申请数量
      // data?.MinNum = data
      //     ?.DemandNum; //fixme 防止 MinNum与DemandNum不同；物料请购提交服务器使用的申请数量是MinNum这个字段；（请购申请，物料请购时，注意。）
      // print(
      //     "申请数量=======================MinNum:${data?.MinNum}\tDemandNum:${data?.DemandNum}");
      var NumberOfApplications2 = StatefulBuilder(
        builder: (contxet, setState) {
          NumberOfApplications = setState;
          return UiBase.itemWithSigleEdit(
              context, StringUtils.toStringAsDecimal(data?.DemandNum),
              isAllowEmpty: true,
              isDecimal: true,
              readOnly: true,
              unit: data?.MainUnit ?? "",
              isNegative: false, onChanged: (value) {
            data?.DemandNum = value;
            data?.MinNum = value;
            SubsidiaryNumSetState?.call(() {}); //原片辅助数量(面积)
          });
        },
      );
      rowChildren.add(NumberOfApplications2);

      //批准数量
      var NumberOfApplications3 = StatefulBuilder(
        builder: (contxet, setState) {
          NumberOfApplications = setState;
          return UiBase.itemWithSigleEdit(
              context, StringUtils.toStringAsDecimal(data?.ApproveNum),
              isAllowEmpty: true,
              isDecimal: true,
              unit: data?.MainUnit ?? "",
              isNegative: false, onChanged: (value) {
            data?.ApproveNum = value;
            SubsidiaryNumSetState?.call(() {}); //原片辅助数量(面积)
          });
        },
      );
      rowChildren.add(NumberOfApplications3);

      if (firstData.isSubsidiaryNum()) {
        //面积
        var StockArea = StatefulBuilder(
          builder: (contxet, setState) {
            SubsidiaryNumSetState = setState;
            return _text(data?.SubsidiaryNum3());
          },
        );
        rowChildren.add(StockArea);
      }

      //品牌
      var ManufacturerName = StatefulBuilder(
        builder: (contxet, setState) {
          SubsidiaryNumSetState = setState;
          return _text(data?.ManufacturerName);
        },
      );
      rowChildren.add(ManufacturerName);

      ///当前库存
      var CurrentInventory = StatefulBuilder(
        builder: (contxet, setState) {
          CurrentInventorySetState = setState;
          var CurrentInventory = _text(data?.StockNum2());
          return CurrentInventory;
        },
      );
      rowChildren.add(CurrentInventory);
      //备注
      if (isModifyBeizhu) {
        //可以填写
        var ListBeizhu = StatefulBuilder(
          builder: (contxet, setState) {
            sizeSetState = setState;
            return UiBase.itemWithSigleEdit(context, data?.ListBeizhu,
                isAllowEmpty: true, isLine: true, onChanged: (value) {
              data?.ListBeizhu = value;
            });
          },
        );
        rowChildren.add(ListBeizhu);
      } else {
        var ListBeizhu = _text("${data?.ListBeizhu}");
        rowChildren.add(ListBeizhu);
      }
      //操作
      if (isAdd) {
        if (i == 0) {
          var Operation = AppUi.getEmptyView();
          rowChildren.add(Operation);
        } else {
          var Operation =
              _materialButton(AppStrings.of(context).delete, onPressed: () {
            //删除
            _setState?.call(() {
              datas?.removeAt(i);
            });
          });
          rowChildren.add(Operation);
        }
      }
      var tableRow = TableRow(
          // decoration: BoxDecoration(color: _getColor(_index + 1)),
          decoration: BoxDecoration(color: _getColor(i)),
          children: rowChildren);
      children.add(tableRow);
    }
    var table = Table(
      border: TableBorder.all(
          color: _BorderColor, width: _width, style: BorderStyle.solid),
      defaultVerticalAlignment: TableCellVerticalAlignment.middle,
      columnWidths: {
        0: IntrinsicColumnWidth(),
        1: IntrinsicColumnWidth(),
        2: IntrinsicColumnWidth(),
        3: IntrinsicColumnWidth(),
        4: IntrinsicColumnWidth(),
        5: IntrinsicColumnWidth(),
        6: IntrinsicColumnWidth(),
        7: IntrinsicColumnWidth(),
        8: IntrinsicColumnWidth(),
        9: IntrinsicColumnWidth(),
        10: IntrinsicColumnWidth(),
        11: IntrinsicColumnWidth(),
        12: IntrinsicColumnWidth(),
        13: IntrinsicColumnWidth(),
        14: IntrinsicColumnWidth(),
        15: IntrinsicColumnWidth(),
        16: IntrinsicColumnWidth(),
        17: IntrinsicColumnWidth(),
        18: IntrinsicColumnWidth(),
        19: IntrinsicColumnWidth(),
      },
      children: children,
    );
    return table;
  }

  ///获取库存数量
  static getStockNum(BuildContext context,
      StateSetter? CurrentInventorySetState, PurDemand data) {
    ///data?.StockNum
    MaterialModel.getStockNum(context, data, false, (value) {
      if (value.isSuccessForCode()) {
        CurrentInventorySetState?.call(() {
          data?.StockNum = value.StockNum;
          //print("物料请购库存：${data?.StockNum}");
        });
      }
    });
  }

  //fixme 条目颜色背景
  static Color _getColor(int i) {
    Color _color = _backgroundColorWithWhite;
    //print("=============$i ${i%2}");
    if (i % 2 == 0) {
      _color = _backgroundColorWithGrey;
    }
    return _color;
  }

  //文本
  static Widget _text(String? text, {bool isStart = false}) {
    // return Center(
    //   child: Text(text ?? ""),
    // );
    Widget child;
    if (isStart) {
      var textKey = Text(
        text ?? "",
        style: AppStyle.textStyleWithCard(),
      );
      var value = "*";
      var startText = Text(
        value,
        softWrap: true,
        style: AppStyle.textStyleWithCardRed(),
      );
      child = SizedBox(
        child: Row(
          children: [textKey, startText],
          mainAxisAlignment: MainAxisAlignment.center,
        ),
        width: 120,
      );
    } else {
      child = Text(text ?? "");
    }
    return Center(
      child: ConstrainedBox(
        constraints: BoxConstraints(
          minHeight: 36.0, //最小高度
        ),
        child: Center(
          child: child,
        ),
      ),
    );
  }

  //复选框
  //isChecked 是否选中
  //isEnable 是否可操作
  //onChanged 选中回调
  static Widget _checkbox(bool isChecked,
      {bool isEnable = true, Function(bool)? onChanged}) {
    Color activeColor = Colors.blueAccent;
    Color inactiveColor = Colors.black;
    if (!isEnable) {
      //不可用，颜色变暗。
      activeColor = Colors.black12;
      inactiveColor = Colors.black12;
    }
    return Container(
      alignment: Alignment.center,
      // height: 30,
      // width: 30,
      padding: EdgeInsets.zero,
      margin: EdgeInsets.zero,
      child: CircleCheckbox(
        isEnable: isEnable,
        value: isChecked,
        //value 是否选中
        width: 20,
        //width 宽度
        height: 20,
        //height 高度
        activeColor: activeColor,
        //activeColor 选中时背景颜色
        inactiveColor: inactiveColor,
        //inactiveColor 未选中时颜色
        style: CircleCheckboxStyle.tick_hollow,
        //circle_point 圆点样式
        //checked: , 自定义选中组件；fixme 优先级比以上属性设置要高。
        //unChecked: ,自定义未选中组件
        onChanged: (bool) {
          //选中状态改变时回调，如点击时。
          //选中状态改变时回调。
          //setState(() {});
          if (isEnable) {
            onChanged?.call(bool);
          }
        },
      ),
    );
  }

  ///按钮
  static Widget _materialButton(String text,
      {VoidCallback? onPressed,
      double radius = 5,
      double height = 35,
      double width = 50,
      Color color = Colors.blueAccent,
      Color textColor = Colors.white,
      double fontSize = 14,
      EdgeInsetsGeometry margin = const EdgeInsets.only(left: 8, right: 8),
      EdgeInsetsGeometry padding =
          const EdgeInsets.only(left: 16, right: 16)}) {
    return Container(
      margin: margin,
      child: MaterialButton(
        padding: padding,
        height: height,
        minWidth: width,
        onPressed: () {
          onPressed?.call();
        },
        //label 右边控件（一般为文本），不能为空
        color: color,
        //color 按钮颜色
        splashColor: Colors.black12,
        //splashColor 点击时，飞溅扩散的颜色
        //highlightColor: Colors.red, //highlightColor 点击时按钮颜色
        colorBrightness: Brightness.light,
        //colorBrightness 按钮亮度；Brightness.dark 暗系风格;Brightness.light 高亮(默认)
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(radius))),
        //shape 形状
        textColor: Colors.white,
        //文本默认颜色
        child: Text(
          text,
          style: TextStyle(
            color: textColor,
            fontSize: fontSize,
          ),
        ), //fixme 子控件
      ),
    );
  }
}
